package work.tree;

import work.TreeNode;

public class Problem108 {

    public TreeNode sortedArrayToBST(int[] nums) {
        TreeNode dfs = DFS(nums, 0, nums.length);
        return dfs;
    }

    public TreeNode DFS(int[] nums, int start, int end) {
        if (start >= end) return null;
        int mid = (start + end) / 2;
        TreeNode treeNode = new TreeNode(nums[mid]);
        treeNode.left = DFS(nums, start, mid - 1);
        treeNode.right = DFS(nums, mid + 1, end);
        return treeNode;
    }

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode();
        int[] nums =new int[]{-10,-3,0,5,9};
        Problem108 problem108 = new Problem108();
        problem108.sortedArrayToBST(nums);
    }
}
